package com.xinyuan.digit.next.api;


import com.alibaba.fastjson2.annotation.JSONField;
import com.xinyuan.digit.next.common.LongToStringSerializer;

import java.io.Serializable;
import java.util.Date;

/**
 * 基础bean
 *
 * @author viperasi 2017/07/01
 * @version 1.2.2
 */
public abstract class BaseEntity implements Serializable {
    /**
     * 序列ID
     * 数据结构（bigint）
     */
    @JSONField(serializeUsing = LongToStringSerializer.class)
    protected Long id;

    /**
     * 创建时间
     * 数据结构（datetime）
     *
     * @mock @datetime
     * @readOnly
     */
    @JSONField(format = "yyyy-MM-dd HH:mm:ss")
    protected Date createAt;

    /**
     * 最后更新时间
     * 数据结构（datetime）
     *
     * @mock @datetime
     * @readOnly
     */
    @JSONField(format = "yyyy-MM-dd HH:mm:ss")
    protected Date updateAt;

    /**
     * 是否启用，0为不启用，1为已启用
     * 数据结构（integer）
     *
     * @readOnly
     */
    protected Integer released;

    /**
     * 是否已删除, 0为未删除 1为已删除, 默认为0
     * 数据结构（integer）
     *
     * @readOnly
     */
    protected Integer deleted;

    public Long getId() {
        return id;
    }

    public BaseEntity setId(Long id) {
        this.id = id;
        return this;
    }

    public Date getCreateAt() {
        return createAt;
    }

    public BaseEntity setCreateAt(Date createAt) {
        this.createAt = createAt;
        return this;
    }

    public Date getUpdateAt() {
        return updateAt;
    }

    public BaseEntity setUpdateAt(Date updateAt) {
        this.updateAt = updateAt;
        return this;
    }

    public Integer getReleased() {
        return released;
    }

    public BaseEntity setReleased(Integer released) {
        this.released = released;
        return this;
    }

    public Integer getDeleted() {
        return deleted;
    }

    public BaseEntity setDeleted(Integer deleted) {
        this.deleted = deleted;
        return this;
    }

    @JSONField(serialize = false)
    public boolean isDel() {
        return this.deleted != null && this.deleted == 1;
    }
}
